package com.zhoukx.command;

/**
 * @ClassName RemoteController
 * @Description:
 * @Author zhoukx
 * @Date 2020/8/17
 **/
public class RemoteController {

    //执行开操作
    Command[] onCommands;

    Command[] offCommands;

    // 执行撤销命令
    Command undoCommand;

    public RemoteController(){
        onCommands = new Command[5];
        offCommands = new Command[5];
        for (int i = 0; i <5 ; i++) {
            onCommands[i] = new NoCommand();
            offCommands[i] = new NoCommand();
        }
    }

    // 给我的按钮设置需要的命令
    public void setCommand(int no,Command onCommand,Command offCommand){
       onCommands [no] = onCommand;
       offCommands [no] = offCommand;
    }

    // 按下开的按钮
    public void onButtonWasPused(int no){
        // 找到你按下开的按钮，并调用对象的方法
        onCommands[no].execute();
        // 记录这次的操作，用于撤销
        undoCommand = onCommands[no];
    }

    // 按下关闭的按钮
    public void offButtonWasPused(int no){
        // 找到你按下开的按钮，并调用对象的方法
        offCommands[no].undo();
        // 记录这次的操作，用于撤销
        undoCommand = offCommands[no];
    }
    // 按下撤销那妞
    public void  undoButtonWasPushed(){
        undoCommand.undo();
    }
}
